package socketmvc.server.context;

import org.tio.core.TioConfig;
import org.tio.utils.lock.ListWithLock;
import socketmvc.core.config.SocketMvcConfig;
import socketmvc.core.lambda.DoubleValConsumer;
import socketmvc.core.packets.basic.IPacket;
import socketmvc.server.SocketServerStarter;

import java.util.List;

public interface IServerContext {

    Object getAttr(String key);
    Object setAttr(String key, Object val);
    SocketServerStarter getServer();
    TioConfig getIoConfig();
    SocketMvcConfig getMvcConfig();
    List<IChannelContext> getByUser(String user);
    ListWithLock<IChannelContext> getByUserWithLock(String user);
    List<IChannelContext> getByGroup(String group);
    ListWithLock<IChannelContext> getByGroupWithLock(String group);
    IChannelContext getByCurrentThread();
    void send(ListWithLock<IChannelContext> contexts, IPacket packet);
    void send(List<IChannelContext> contexts,IPacket packet);
    void send(IChannelContext context,IPacket packet);
    void sendToUser(String user, IPacket packet);
    void sendToUserNullable(String user, IPacket packet, DoubleValConsumer<String,IPacket> nullableCall);
    void sendToGroup(String group, IPacket packet);
    void sendToGroupNullable(String group, IPacket packet, DoubleValConsumer<String,IPacket> nullableCall);
    void sendToCurrentThread(IPacket packet);
    void bindUser(IChannelContext context,String user);
    void bindGroup(IChannelContext context,String group);
    void unbindUser(IChannelContext context,String user);
    void unbindUser(String user);
    void unbindGroup(IChannelContext context,String group);
    void unbindGroup(String user,String group);
    boolean getUserIsOnline(String user);
    void close(IChannelContext context);
    void close(List<IChannelContext> context);
    void close(ListWithLock<IChannelContext> context);

    /**
     * 将客户端设置进黑名单
     */
    void setContextToBlacklist(IChannelContext context);

    /**
     * 从黑名单中删除客户端
     */
    void delContextFromBlacklist(IChannelContext context);

    /**
     * 查看客户端是否在黑名单中
     * @return true在黑名单中，false不在
     */
    boolean isContextInBlacklist(IChannelContext context);

}
